<script>
	/**
	 * vuex管理登陆状态，具体可以参考官方登陆模板示例
	 */
	import {
		mapMutations
	} from 'vuex';

	import {
		BASE_URL
	} from '@/config/app';
	export default {
		methods: {
			// 设置主题
			async getTheme() {
				let res = await this.$api.home.getTheme.get()
				let theme = res.data.miniapp_home_theme
				let selectedColor = '';
				let index = 2;

				let styles = {
					theme1: {
						bg1: '#e93323',
						bg2: '#ff2c3c',
						color: '#e93323'
					},
					theme2: {
						bg1: '#f7971e',
						bg2: '#ffd200',
						color: '#f7971e',
					},
					theme3: {
						bg1: '#fa444d',
						bg2: '#fd498f',
						color: '#fa444d',
					},
					theme4: {
						bg1: '#e0a356',
						bg2: '#e0a356',
						color: '#e0a356',
					},
					theme5: {
						bg1: '#2f80ed',
						bg2: '#56ccf2',
						color: '#2f80ed',
					},
					theme6: {
						bg1: '#2ec840',
						bg2: '#3de650',
						color: '#2ec840',
					}
				}

				if (theme == 'red') {
					uni.setStorageSync('theme', {
						bg1: styles.theme1.bg1,
						bg2: styles.theme1.bg2,
						color: styles.theme1.color
					})
					selectedColor = styles.theme1.color
				} else if (theme == 'orange') {
					uni.setStorageSync('theme', {
						bg1: styles.theme2.bg1,
						bg2: styles.theme2.bg2,
						color: styles.theme2.color
					})
					selectedColor = styles.theme2.color
					index = 3
				} else if (theme == 'pink') {
					uni.setStorageSync('theme', {
						bg1: styles.theme3.bg1,
						bg2: styles.theme3.bg2,
						color: styles.theme3.color
					})
					selectedColor = styles.theme3.color
					index = 4
				} else if (theme == 'gold') {
					uni.setStorageSync('theme', {
						bg1: styles.theme4.bg1,
						bg2: styles.theme4.bg2,
						color: styles.theme4.color
					})
					selectedColor = styles.theme4.color
					index = 5
				} else if (theme == 'blue') {
					uni.setStorageSync('theme', {
						bg1: styles.theme5.bg1,
						bg2: styles.theme5.bg2,
						color: styles.theme5.color
					})
					selectedColor = styles.theme5.color
					index = 6
				} else if (theme == 'green') {
					uni.setStorageSync('theme', {
						bg1: styles.theme6.bg1,
						bg2: styles.theme6.bg2,
						color: styles.theme6.color
					})
					selectedColor = styles.theme6.color
					index = 7
				}

				// uni.setTabBarStyle({
				// 	"color": "#393D49",
				// 	"selectedColor": selectedColor,
				// 	"borderStyle": "black",
				// 	"backgroundColor": "#ffffff",
				// })

				// uni.setTabBarItem({
				// 	index: 0,
				// 	text: '首页',
				// 	iconPath: 'static/theme/1-001.png',
				// 	selectedIconPath: 'static/theme/1-00' + index + '.png'
				// })

				// uni.setTabBarItem({
				// 	index: 1,
				// 	text: '分类',
				// 	iconPath: 'static/theme/2-001.png',
				// 	selectedIconPath: 'static/theme/2-00' + index + '.png'
				// })

				// uni.setTabBarItem({
				// 	index: 2,
				// 	text: '购物车',
				// 	iconPath: 'static/theme/3-001.png',
				// 	selectedIconPath: 'static/theme/3-00' + index + '.png'
				// })

				// uni.setTabBarItem({
				// 	index: 3,
				// 	text: '我的',
				// 	iconPath: 'static/theme/4-001.png',
				// 	selectedIconPath: 'static/theme/4-00' + index + '.png'
				// })

				uni.setStorageSync('cate_style', res.data.cate_style)


			}
		},
		globalData: {
			privacyContractName: '', //隐私协议名称 是接口生成的！
			showPrivacy: false //全局控制弹窗显隐
		},
		onLaunch: function() {
			// uni.hideTabBar();
			// #ifdef MP
			const that = this;
			wx.getPrivacySetting({
				success(res) {
					if (res.needAuthorization) {
						that.globalData.privacyContractName = res.privacyContractName;
						that.globalData.showPrivacy = true;
					} else {
						that.globalData.showPrivacy = false;
					}
				}
			});
			// #endif
			this.getTheme()


		},
		onShow: function() {

		},
		onReady: function() {
			
		},
		onHide: function() {

		},
	}
</script>

<style lang='scss'>
	@import "@/static/alifont/iconfont.css";
	@import "@/uni.scss";

	view,
	scroll-view,
	swiper,
	swiper-item,
	cover-view,
	cover-image,
	icon,
	text,
	rich-text,
	progress,
	button,
	checkbox,
	form,
	input,
	label,
	radio,
	slider,
	switch,
	textarea,
	navigator,
	audio,
	camera,
	image,
	video {
		box-sizing: border-box;
	}

	/* 骨架屏替代方案 */
	.Skeleton {
		background: #f3f3f3;
		padding: 20upx 0;
		border-radius: 8upx;
	}

	/* App.vue */
	page {
		/* padding-bottom: 100rpx; */
		/* 与 TabBar 高度一致 */
	}

	/* 图片载入替代方案 */
	.image-wrapper {
		font-size: 0;
		background: #f3f3f3;
		border-radius: 4px;

		image {
			width: 100%;
			height: 100%;
			transition: .6s;
			opacity: 0;

			&.loaded {
				opacity: 1;
			}
		}
	}

	.clamp {
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
		display: block;
	}

	.common-hover {
		background: #f5f5f5;
	}

	/*边框*/
	.b-b:after,
	.b-t:after {
		position: absolute;
		z-index: 3;
		left: 0;
		right: 0;
		height: 0;
		content: '';
		transform: scaleY(.5);
	}

	.bottom-safe {
		margin-bottom: constant(safe-area-inset-bottom);
		/* 兼容iOS < 11.2 */
		margin-bottom: env(safe-area-inset-bottom);
		/* 兼容iOS 11.2及以上 */
	}

	.b-b:after {
		bottom: 0;
	}

	.b-t:after {
		top: 0;
	}

	/* button样式改写 */
	uni-button,
	button {
		height: 80upx;
		line-height: 80upx;
		font-size: $font-lg + 2upx;
		font-weight: normal;

		&.no-border:before,
		&.no-border:after {
			border: 0;
		}
	}

	uni-button[type=default],
	button[type=default] {
		color: $font-color-dark;
	}

	/* input 样式 */
	.input-placeholder {
		color: #999999;
	}

	.placeholder {
		color: #999999;
	}

	uni-page-wrapper {
		background: #f5f5f5;
	}

	.round .uni-checkbox-input {
		border-radius: 50%;
		width: 19px;
		height: 19px;
	}

	.round .uni-checkbox-input.uni-checkbox-input-checked {
		border: 1px solid #e93323 !important;
		background-color: #e93323 !important;
		color: #fff !important;
	}

	::-webkit-scrollbar {
		display: none;
		width: 0 !important;
		height: 0 !important;
		-webkit-appearance: none;
		background: transparent;
	}
</style>